import Vue from 'vue'
import Router from 'vue-router'
import basicsDataAdmin from './modules/basicsDataAdmin'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import employee from '@/router/modules/employee' // 员工管理
import vehicle from '@/router/modules/vehicle' // 车辆管理

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard' }
    }]
  },
  basicsDataAdmin,
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: '业务管理',
      icon: 'table'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: '订单管理' }

      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: { title: '运单管理' }
      },
      {
        path: '/nested/menu1/detail/:id?', // 员工详情的地址
        component: () => import('@/views/nested/menu1/detail.vue'),
        hidden: true, // 表示隐藏在左侧菜单
        meta: {
          title: '订单详情' // 显示在导航的文本
        }
      },
      {
        path: '/nested/menu2/detail1/:id?', // 员工详情的地址
        component: () => import('@/views/nested/menu2/detail1.vue'),
        hidden: true, // 表示隐藏在左侧菜单
        meta: {
          title: '运单详情' // 显示在导航的文本
        }
      }

    ]
  },
  // 员工管理
  employee,
  // 车辆管理
  vehicle,

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
